﻿
#region Copyright & License
// --------------------------
// Copyright 2008 Daniel Gray
// --------------------------
// This file is part of Kale.
//
// Kale is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Kale is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Kale.  If not, see <http://www.gnu.org/licenses/>.
#endregion
#region File details
// --------------------------------------------------------
// Filename          : NodeCacheHelper.cs
// Author            : Daniel Gray
// Created           : 17/04/2008
// --------------------------------------------------------
#endregion
            
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kale.Core.Configuration;

namespace Kale.Core
{
   public static class NodeCacheHelper
   {
      private static INodeCache _cache;

      public static INodeCache Cache
      {
         get
         {
            return _cache;
         }
      }

      static NodeCacheHelper()
      {
         _cache = CreateCacheFromConfig(KaleConfigurationSection.Default.NodeCaching);
      }

      public static INodeCache CreateCacheFromConfig(NodeCachingElement configElement)
      {
         INodeCache cache = null;

         switch (configElement.Type)
         {
            case NodeCacheType.None:
               cache = new NoNodeCache();
               break;
            case NodeCacheType.Simple:
               cache = new SimpleNodeCache();
               break;
            case NodeCacheType.Complex:
               cache = new ComplexNodeCache(configElement.SecondsBetweenModificationChecks,
                                             configElement.ExpirationType,
                                             configElement.ExpirationMinutes,
                                             configElement.Priority);
               break;
         }

         return cache;
      }
   }
}
